package com.turnengine.client.local.action.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Action.
 */
public class Action implements IAction, Comparable<IAction> {

	/** The action id. */
	private int actionId = -1;
	/** The turns. */
	private int turns = -1;
	/** The limit. */
	private int limit = -1;

	/**
	 * Creates a new Action.
	 */
	public Action() {
	}

	/**
	 * Creates a new Action.
	 * @param actionId the action id
	 * @param turns the turns
	 * @param limit the limit
	 */
	public Action(int actionId, int turns, int limit) {
		setActionId(actionId);
		setTurns(turns);
		setLimit(limit);
	}

	/**
	 * Creates a new Action.
	 * @param action the action
	 */
	public Action(Action action) {
		setActionId(action.getActionId());
		setTurns(action.getTurns());
		setLimit(action.getLimit());
	}

	/**
	 * Creates a new Action.
	 * @param iAction the i action
	 */
	public Action(IAction iAction) {
		setActionId(iAction.getActionId());
		setTurns(iAction.getTurns());
		setLimit(iAction.getLimit());
	}

	/**
	 * Returns the action id.
	 * @return the action id.
	 */
	public int getActionId() {
		return actionId;
	}

	/**
	 * Returns the turns.
	 * @return the turns.
	 */
	public int getTurns() {
		return turns;
	}

	/**
	 * Returns the limit.
	 * @return the limit.
	 */
	public int getLimit() {
		return limit;
	}

	/**
	 * Sets the action id.
	 * @param actionId the action id to set.
	 */
	public void setActionId(int actionId) {
		this.actionId = actionId;
	}

	/**
	 * Sets the turns.
	 * @param turns the turns to set.
	 */
	public void setTurns(int turns) {
		this.turns = turns;
	}

	/**
	 * Sets the limit.
	 * @param limit the limit to set.
	 */
	public void setLimit(int limit) {
		this.limit = limit;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(367, 37);
		hash.append(actionId);
		hash.append(turns);
		hash.append(limit);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Action) {
			Action compare = (Action) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.actionId, compare.actionId);
			equals.append(this.turns, compare.turns);
			equals.append(this.limit, compare.limit);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IAction compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.actionId, compare.getActionId());
		builder.append(this.turns, compare.getTurns());
		builder.append(this.limit, compare.getLimit());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("actionId", actionId);
		string.append("turns", turns);
		string.append("limit", limit);
		return string.toString();
	}
}
